package com.ruoyi.web.controller.vote;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.detail.domain.HouseVoteScoreDetail;
import com.ruoyi.detail.service.IHouseVoteScoreDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 投票明细Controller
 * 
 * @author ruoyi
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/vote/detail")
public class HouseVoteScoreDetailController extends BaseController
{
    @Autowired
    private IHouseVoteScoreDetailService houseVoteScoreDetailService;

    /**
     * 查询投票明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseVoteScoreDetail houseVoteScoreDetail)
    {
        startPage();
        List<HouseVoteScoreDetail> list = houseVoteScoreDetailService.selectHouseVoteScoreDetailList(houseVoteScoreDetail);
        return getDataTable(list);
    }

    /**
     * 导出投票明细列表
     */
    @Log(title = "投票明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseVoteScoreDetail houseVoteScoreDetail)
    {
        List<HouseVoteScoreDetail> list = houseVoteScoreDetailService.selectHouseVoteScoreDetailList(houseVoteScoreDetail);
        ExcelUtil<HouseVoteScoreDetail> util = new ExcelUtil<HouseVoteScoreDetail>(HouseVoteScoreDetail.class);
        util.exportExcel(response, list, "投票明细数据");
    }

    /**
     * 获取投票明细详细信息
     */
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return AjaxResult.success(houseVoteScoreDetailService.selectHouseVoteScoreDetailByDetailId(detailId));
    }

    /**
     * 新增投票明细
     */
     @Log(title = "投票明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseVoteScoreDetail houseVoteScoreDetail)
    {
        return toAjax(houseVoteScoreDetailService.insertHouseVoteScoreDetail(houseVoteScoreDetail));
    }

    /**
     * 修改投票明细
     */
    @Log(title = "投票明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseVoteScoreDetail houseVoteScoreDetail)
    {
        return toAjax(houseVoteScoreDetailService.updateHouseVoteScoreDetail(houseVoteScoreDetail));
    }

    /**
     * 删除投票明细
     */
    @Log(title = "投票明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(houseVoteScoreDetailService.deleteHouseVoteScoreDetailByDetailIds(detailIds));
    }
}
